export enum ErrorType {
    BAD_REQUEST = 'BAD_REQUEST',
    UNAUTHORIZED = 'UNAUTHORIZED',
    FORBIDDEN = 'FORBIDDEN',
    NOT_FOUND = 'NOT_FOUND',
    INTERNAL_SERVER_ERROR = 'INTERNAL_SERVER_ERROR',
    VALIDATION_ERROR = 'VALIDATION_ERROR'
}

export interface ErrorResponse {
    code: number;
    type: ErrorType;
    message: string;
    details?: unknown;
}

export class AppError extends Error {
    public readonly type: ErrorType;
    public readonly statusCode: number;
    public readonly details?: unknown;

    constructor(type: ErrorType, message: string, statusCode: number, details?: unknown) {
        super(message);
        this.type = type;
        this.statusCode = statusCode;
        this.details = details;
        Object.setPrototypeOf(this, AppError.prototype);
    }
}

export class BadRequestError extends AppError {
    constructor(message: string, details?: unknown) {
        super(ErrorType.BAD_REQUEST, message, 400, details);
    }
}

export class UnauthorizedError extends AppError {
    constructor(message: string = 'Unauthorized', details?: unknown) {
        super(ErrorType.UNAUTHORIZED, message, 401, details);
    }
}

export class ForbiddenError extends AppError {
    constructor(message: string = 'Forbidden', details?: unknown) {
        super(ErrorType.FORBIDDEN, message, 403, details);
    }
}

export class NotFoundError extends AppError {
    constructor(message: string = 'Resource not found', details?: unknown) {
        super(ErrorType.NOT_FOUND, message, 404, details);
    }
}

export class ValidationError extends AppError {
    constructor(message: string, details?: unknown) {
        super(ErrorType.VALIDATION_ERROR, message, 400, details);
    }
}

export class InternalServerError extends AppError {
    constructor(message: string = 'Internal Server Error', details?: unknown) {
        super(ErrorType.INTERNAL_SERVER_ERROR, message, 500, details);
    }
} 